#ifndef __IO_CONTEXT_POOL_H__
#define __IO_CONTEXT_POOL_H__

#include <boost/asio.hpp>
#include <memory>
#include <vector>
#include <thread>

class IOContextPool
{
public:
    using IOContext = boost::asio::io_context;
    using Work = boost::asio::io_context::work;
    using WorkPtr = std::unique_ptr<Work>;

    IOContextPool(std::size_t size = std::thread::hardware_concurrency());
    ~IOContextPool();

    void stop();
    IOContext& get_io_context();

    std::size_t get_thread_count() const { return _thread_count; }    
private:

    std::vector<IOContext> _io_contexts;
    std::vector<WorkPtr> _works;
    std::vector<std::thread> _threads;
    std::size_t _next;
    std::size_t _thread_count;
};



#endif // !__IO_CONTEXT_POOL_H__

